package com.platform.modules.wallet.take;

import cn.hutool.core.date.DateUtil;
import com.platform.modules.wallet.domain.WalletRedPacketSub;
import com.platform.modules.wallet.domain.WalletTransfer;
import com.platform.modules.wallet.service.WalletRedPacketSubService;
import com.platform.modules.wallet.service.WalletTransferService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class RefundTask {

    @Autowired
    private WalletTransferService walletTransferService;
    @Autowired
    private WalletRedPacketSubService walletRedPacketSubService;

    /**
     * 定时退款
     */
    @Scheduled(cron = "0 * * * * ?")//"0 5/10 9-23 * * ?"
    public void runRefund() {

//        walletTransferService.refund(1554666929860960257l);//测试退款
//        walletRedPacketSubService.refund(1554369099934015490l);

        List<WalletTransfer> refun = walletTransferService.getRefun();

        for (WalletTransfer transfer : refun) {
            walletTransferService.refund(transfer.getId());//测试退款
            log.info(transfer.toString());
        }

        List<WalletRedPacketSub> subList = walletRedPacketSubService.getRefun();
        for (WalletRedPacketSub walletRedPacketSub : subList) {
            walletRedPacketSubService.refund(walletRedPacketSub.getId());
            log.info(walletRedPacketSub.toString());
        }

        System.out.println("这是每分钟" + DateUtil.date());
    }
}
